import { createVNode } from 'vue';
import { Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { useUserStore } from '@/store';
import { handleSuccess } from './index';

let instance = null;
/**
 * 重新登录
 *
 * @param {Object} http
 * @param {Object} res 响应数据
 * @returns {Promise}
 */
export function handleLoginAgain(_, res) {
  const userStore = useUserStore();
  if (instance === null) {
    instance = Modal.info({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: res.data.message,
      okText: '确定',
      onOk: () => {
        userStore.resetStore();
        instance = null;
      },
    });
  }

  return handleSuccess(_, res);
}
